﻿using ConfExpert.Forms.Base;
using DevTeam;


using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class Price7C : XForm
    {
        public Price7C()
        {
            InitializeComponent();
        }

        DateTime Tarih = new DateTime(2000, 1, 1);
        BindingSource bs, bsTop;
        private void Price7C_Load(object sender, EventArgs e)
        {

            //ds.xPrice7C1.Columns["TotalQty"].Expression = "SUM(Child(FK_xPrice7C2_xPrice7C1_ProductId).Qty)";
            ds.xPrice7C1.Columns["ShirtPrice"].Expression = "(Price * 1.05 * 1.75) + 5.40";
            bs = new BindingSource(ds, "xPrice7C1");
            bsTop = new BindingSource(bs, "FK_xPrice7C2_xPrice7C1_ProductId");

            InitGridView(gridView1, bs);
            gridView1.MakeColumnInvisible("ProductId");
            gridView1.AddSummary("TotalQty");

            InitGridView(gridView2, bsTop);
            gridView2.MakeColumnInvisible("ProductId", "Scan");
            foreach (string str in "Price;ShirtPrice".Split(';'))
            {
                gridView1.Columns[str].Caption += gridView1.Columns[str].FieldName + " €";
                gridView1.Columns[str].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                gridView1.Columns[str].DisplayFormat.FormatString = "#,###.00";
            }

            gridView2.Columns["Qty"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            gridView2.Columns["Qty"].DisplayFormat.FormatString = "#,###";
            gridView2.Columns["Qty"].Caption = "Qty Mt";
            gridView2.AddSummary("Qty");

            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridView1_FocusedRowChanged);
            gridView1.ShowingEditor += new System.ComponentModel.CancelEventHandler(gridView1_ShowingEditor);
            gridView2.ShowingEditor += new System.ComponentModel.CancelEventHandler(gridView2_ShowingEditor);

            checkEdit1.CheckedChanged += checkEdit1_CheckedChanged;
            gleCustomer.Edit.Assign(RI(Rp.V_Customer));
            gleCustomer.EditValueChanged += new EventHandler(gleCustomer_EditValueChanged);
            gleCustomer.EditValue = 20;

            //((RepositoryItemGridLookUpEdit)gridView1.Columns["Grup7C"].ColumnEdit).EditValueChanged += new EventHandler(Price7C_EditValueChanged);
            splitContainerControl1.AutoSize();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            bs.EndEdit();
            bsTop.EndEdit();
            ExecuteNonQuery("UpdPrice7C", intParse(gleCustomer.EditValue), checkEdit1.Checked, ds.xPrice7C1.SerializeChanges(), ds.xPrice7C2.SerializeChanges());
            Rfrsh();
        }

        void checkEdit1_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ds.Clear();
            Tarih = new DateTime(2000, 1, 1);
            Rfrsh();
        }

        void Rfrsh()
        {
            GetDetails("xPrice7C1;xPrice7C2;xTarih", "GetPrice7C", intParse(gleCustomer.EditValue), checkEdit1.Checked, Tarih);
            Tarih = ds.xTarih[0].Tarih;
            gridView1.BestFitColumns();
        }

        void gleCustomer_EditValueChanged(object sender, EventArgs e)
        {
            ds.Clear();
            Tarih = new DateTime(2000, 1, 1);
            Rfrsh();
        }

        void Price7C_EditValueChanged(object sender, EventArgs e)
        {

        }

        void gridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = gridView1.FocusedColumn.FieldName != "Price" &&
                gridView1.FocusedColumn.FieldName != "Notes" &&
                gridView1.FocusedColumn.FieldName != "KompozisyonId" &&
                gridView1.FocusedColumn.FieldName != "Konstruksiyon" &&
                gridView1.FocusedColumn.FieldName != "Grup7CId";
        }

        void gridView2_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = gridView2.FocusedColumn.FieldName != "BrandId" &&
                gridView2.FocusedColumn.FieldName != "SezonId" &&
                gridView2.FocusedColumn.FieldName != "OwnerId" &&
                gridView2.FocusedColumn.FieldName != "VendorId";
        }


        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            txtInfo.Caption = gridView1.GetFocusedRowCellDisplayText("ProductId");
            //ExpandCollapse(splitContainerControl1, bsLines.Count > 0 ? AcKapa.Expand : AcKapa.Collapse);
        }
    }
}